import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { TypeOrmCrudService } from '@dataui/crud-typeorm';

import { User } from './user.entity';
import { MoreThan } from 'typeorm';

@Injectable()
export class UsersService extends TypeOrmCrudService<User> {
  constructor(@InjectRepository(User) repo) {
    super(repo);
    this.repo
      .find({
        select: {
          id: true,
          name: {
            first: true,
            last: true,
          },
          email: true,
          company: {
            name: true,
            projects: {
              name: true,
              isActive: true,
            },
          },
        },
        relations: {
          company: {
            projects: true,
          },
          profile: true,
        },
        where: {
          id: MoreThan(3),
          isActive: true,
          company: { id: 1 },
        },
        order: { profile: { name: 'DESC' } },
        take: 5,
        skip: 0,
        withDeleted: true,
      })
      .then((res) => {
        console.log('first', res);
      });
  }
}
